<template>
  <u-container-layout>
    <zlrt-table :p="ctx">
      <template #before>
        <zlrt-search :p="ctx">
          <!-- <template #ownerName>
            <el-select v-model="ctx.filter.ownerId" placeholder="请选择货主">
              <el-option v-for="ite in ownerOptions" :key="ite.id" :label="ite.name" :value="ite.id" />
            </el-select>
          </template> -->
          <template #projectName>
            <!-- <el-form-item label="产品名称" prop="skuName"> -->
              <el-input v-model="ctx.otherFilter.projectName" placeholder="请输入项目名称" />
            <!-- </el-form-item> -->
          </template>
          <template #skuName>
            <!-- <el-form-item label="产品名称" prop="skuName"> -->
              <el-input v-model="ctx.otherFilter.skuName" placeholder="请输入产品名称" />
            <!-- </el-form-item> -->
          </template>
        </zlrt-search>
        <div class="tool-bar">
          <el-button type="danger" v-hasPermit="['wms:product:del']" icon="Delete" :disabled="!ctx.selected.length"
            @click="ctx.batchDelete()">
            批量删除
          </el-button>
          <span style="float:right">
            <!-- <el-upload style="display: inline-block;position: relative;top: 4px;margin-right: 10px;"
                v-model:file-list="importFiles" action="#" multiple
                :http-request="options => ctx.other.upload(options)" :show-file-list="false"> -->
                <el-button type="warning" v-hasPermit="['wms:product:save']" :loading="importLoading" icon="Upload"
                  @click="ctx.other.upload()">
                  上传质检报告
                </el-button>
            <!-- </el-upload> -->
            
            <el-button type="success" v-hasPermit="['wms:product:list']" :loading="ctx.exportLoading" icon="Download"
              @click="ctx.export()">
              导出
            </el-button>
            <!-- <el-button type="primary" v-hasPermit="['wms:product:save']" icon="Plus" @click="ctx.showEdit()">
              添加
            </el-button> -->
          </span>
        </div>
      </template>
      <template v-slot:inspectionImg="scope">
        <el-button v-if="scope.row.inspectionImg" size="small" type="primary" link @click="ctx.other.downInspectionImg(scope.row.inspectionImg)" icon="Link">查询</el-button>
      </template>
      <template v-slot:operation="scope">
        <el-button type="primary" v-hasPermit="['wms:product:save']" link size="small" icon="Edit"
          @click="ctx.showEdit(scope.row)">
          编辑
        </el-button>
        <el-button type="danger" v-hasPermit="['wms:product:del']" link size="small" icon="Delete"
          @click="ctx.del(scope.row.id)">
          删除
        </el-button>
      </template>
      <template #after>
        <el-dialog v-model="ctx.editVisible" :title="ctx.editAction + ctx.title" width="600px" append-to-body
          :close-on-click-modal="false" @close="ctx.closeEdit()">
          <el-form :ref="(e) => ctx.formRef = e" :model="ctx.editData" :rules="ctx.rules" v-loading="ctx.editLoading"
            label-width="120px" class="demo-ruleForm">
            <el-form-item label="项目" prop="projectId">
              <!-- <el-input v-model="ctx.editData.projectId" placeholder="请输入产品编码" /> -->
              <el-select v-model="ctx.editData.projectId" style="width: 100%;" @change="changeProject">
                <el-option v-for="item in projectOptions" :key="item.id" :value="item.id" :label="item.name"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="产品编码" prop="barCode">
              <el-input v-model="ctx.editData.barCode" placeholder="请输入产品编码" />
            </el-form-item>
            <el-form-item label="产品名称" prop="skuName">
              <el-input v-model="ctx.editData.skuName" placeholder="请输入产品名称" />
            </el-form-item>
            <el-form-item label="出厂编号" prop="serialNumber">
              <el-input v-model="ctx.editData.serialNumber" placeholder="请输入出厂编号" />
            </el-form-item>
            <el-form-item label="规格型号" prop="specification">
              <el-input v-model="ctx.editData.specification" placeholder="请输入规格型号" />
            </el-form-item>
            <!-- <el-form-item label="计量单位" prop="unit">
              <el-input v-model="ctx.editData.unit" placeholder="请输入计量单位" />
            </el-form-item> -->
            <!-- <el-form-item label="单价（¥）" prop="price">
              <el-input type="number" v-model="ctx.editData.price" placeholder="请输入单价" />
            </el-form-item> -->
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="ctx.editVisible = false">取消</el-button>
              <el-button type="primary" @click="ctx.save()">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </template>
    </zlrt-table>

    <el-dialog v-model="dialogVisible" title="上传质检报告" width="600px" append-to-body :close-on-click-modal="false">
      <el-form :model="formData">
        <el-form-item>
          <el-upload
            style="width: 550px;"
            drag
            action=""
            show-file-list
            :auto-upload="false"
            multiple
            :on-change="ctx.other.getFile"
          >
            <el-icon class="el-icon--upload"><upload-filled /></el-icon>
            <div class="el-upload__text">
              拖拽上传 <em> 手动上传</em>
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false; fileList = [];">取消</el-button>
          <el-button type="primary" @click="ctx.other.importFile()" :loading="importLoading">确定</el-button>
        </span>
      </template>
    </el-dialog>

  </u-container-layout>
</template>

<script lang="ts" src="./product" />

<style lang="scss" scoped>

</style>
